<?php

/**
 * 品牌控制器
 */
class BrandController extends AuthController{
	public $model;
	public function __init(){
		parent::__init();
		$this->model=K('Brand');
	}
	
	
	/*品牌列表
	 * */
	public function index(){
		if(IS_POST){
		    $this->model->toSort();
		}
		$this->assign('logoData',$this->model->order('sort')->all());
		$this->display();
	}
	
	/*添加品牌
	 * */
	public function addBrand(){
		if(IS_POST){
		    if(!$this->model->addBrand()) $this->error($this->model->error);
		    $this->success('添加成功',U('index'));
		}
		$this->display();
	}
	
	/*编辑品牌信息
	 * */
	public function editBrand(){
		if(IS_POST){
		    if(!$this->model->editBrand()) $this->error($this->model->error);
		    $this->success('修改成功',U('index'));
		}
		$bid=Q('get.bid',0,'intval');
		$this->assign('oldData',$this->model->where("bid={$bid}")->find());
		$this->display();
	}
	
	/*删除品牌
	 * 删除数据库中的数据，删除图片
	 **/
	public function del(){
	    $bid=Q('get.bid',0,'intval');
		$logoPath=$this->model->where("bid={$bid}")->find();
		$this->model->where("bid={$bid}")->delete();
		is_file($logoPath['logo'])&&unlink($logoPath['logo']);
		$this->success('删除成功',U('index'));
	}
	
    /**
     * uploadify上传文件
     */
    public function upload()
    {
        $upload = new Upload('Upload/LogoTemp/');
        $file = $upload->upload();
        if (empty($file)) {
            $this->ajax('上传失败');
        } else {
            $data = $file[0];
            $this->ajax($data);
        }
    }
	
//	/*删除临时logo图片
//	 **/
//	private function delTemp(){
//	    if(!is_dir($this->logoTemp)) return;
//		foreach (glob($this->logoTemp.'/*') as $f) {
//			unlink($f);
//		}
//	}
//	
	
	
	
	
	
	
	
	
	
}




    
    
    
?>